<?php

namespace App\Http\Controllers\Api;

use App\Models\AppVersion;
use App\Models\BoxGame;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class BoxGameController extends Controller
{

    public function appVersion(Request $request)
    {
        $info = AppVersion::query()
            ->where("id","=",1)->first();

        return returnSuccess("成功",$info);
    }

    public function levelDetail(Request $request)
    {
        $level = $request->post("level");
        $detail = BoxGame::query()->where("level","=",$level)->first()->toArray();
        $detail["count"] = BoxGame::query()->count();
        $detail["content"] = json_decode($detail["content"],true);
        $detail["player_start"] = json_decode($detail["player_start"],true);
        return returnSuccess("成功",$detail);
    }

    public function levelList(Request $request)
    {
        $list = BoxGame::query()
            ->orderBy("id","asc")
            ->select(["id","code","name"])
            ->get()->toArray();

        $data = [];
        $arr = [];
        foreach ($list as $key => $val){
            $arr[] = $val;
            if($key>0 && $key%19 == 0){
                $data[] = $arr;
                $arr = [];
            }
        }
        $data[] = $arr;

        return returnSuccess("成功",$data);
    }
}
